#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn];
LL ans[maxn];
map<LL,LL>map1;
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL t;cin>>t;
    while(t--){
        LL n,m;cin>>n>>m;
        map1.clear();
        for(LL i=0;i<=n+10;i++) a[i]=ans[i]=0;
        for(LL i=1;i<=n;i++) cin>>a[i];
        LL now=0;
        for(LL i=1;i<=n;i++){
            if(!map1.count(a[i])){
                ans[i]=++now;
                map1[a[i]]=ans[i];
                continue;
            }
            else{
                LL cnt=map1[a[i]];
                if(cnt>=m) ans[i]=0;
                else{
                    ans[i]=cnt+1;
                    map1[a[i]]=ans[i];
                }
            }
            if(now>m) now=0;
        }
        for(LL i=1;i<=n;i++){
            cout<<ans[i]<<" ";
        }cout<<endl;
        map1.clear();
        for(LL i=1;i<=n;i++){
            if(ans[i]) map1[ans[i]]++;
        }
        LL res=0x3f3f3f3f;
        for(auto i:map1){
            res=min(res,i.second);
        }
        for(LL i=1;i<=n;i++){
            if(ans[i]&&map1[ans[i]]>res){
                map1[ans[i]]--;
                ans[i]=0;
            }
            cout<<ans[i]<<" ";
        }
        cout<<"\n";
    }
   	return 0;
}
